<template >
    <h1 class="title">企业人事管理平台</h1>
    <div class="reset">
      <div class="selectLogin">
      </div>
      <el-card style="width: 400px">
        <template #header>
          <h6 style="text-align: center; color: grey;">请填写您的公司邮箱地址,我们会将新的随机密码发送给您的邮箱。</h6>
        </template>
        <el-form class="demo-form-inline" label-width="auto" style="max-width: 800px">
          <el-form-item label="Email">
            <el-input placeholder="Email" clearable v-model="empReq.empEmail" />
          </el-form-item>
        </el-form>
        <template #footer>
          <div style="display: flex;justify-content: space-between;">
            <el-button type="primary" @click='resetPwd'>重置密码</el-button>
            <router-link to="/loginE"><el-link type="primary"> 返回登陆> </el-link></router-link>
          </div>
        </template>
      </el-card>
    </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import type { EmpReqELogin } from '../model';
import { ElMessage } from 'element-plus';
import { resetPassword } from '../api';
import { useRouter } from 'vue-router';


let empReq = ref<EmpReqELogin>({
  empEmail: '',
  password: ''
})

const router = useRouter()

function resetPwd() {
  // 添加表单验证
  if (!empReq.value.empEmail) {
    ElMessage.error('请输入邮箱地址')
    return
  }

  resetPassword(empReq.value).then(res => {
    if (!res) {
      ElMessage.error('重置密码失败,请稍后重试')
      return
    }
    // 重置成功
    ElMessage.success('新密码已发送至您的邮箱')
    router.push('/loginE')
  }).catch(err => {
    console.error('重置密码错误:', err)
    ElMessage.error('重置密码失败,请稍后重试')
  })
}
</script>
<style scoped>


.title {
  margin-top: 30px;
  text-align: center;
}

.reset {
  width: 800px;
  margin: 100px auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.selectLogin {
  width: 200px;
  display: flex;
  justify-content: space-between;
}
</style>
